package user;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import utils.DomainDAORemote;
import utils.UserDAORemote;
import utils.UsertypeDAORemote;
import dtos.UserDTO;

/**
 * 
 * @author figans
 * 
 *         Contains getters and setter for the edit profile page
 */
@ManagedBean
@RequestScoped
public class EditProfileController {

	@EJB
	UserDAORemote userDAO;
	
	@EJB
	DomainDAORemote domainDAO;
	
	@EJB
	UsertypeDAORemote usertypeDAO;

	UserDTO userDTO;
	String pass;
	String confPass;
//	String verifPass;
	
	String userDomain;
	String usertype;

	String errorMsg = "";
	boolean isError;

	public UserDTO getUserDTO() {
		if (userDTO == null) {
			userDTO = userDAO.getUser(3);
		}
		return userDTO;
	}

	public void setUserDTO(UserDTO userDTO) {
		this.userDTO = userDTO;

	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getConfPass() {
		return confPass;
	}

	public void setConfPass(String confPass) {
		this.confPass = confPass;
	}

//	public String getVerifPass() {
//		return verifPass;
//	}
//
//	public void setVerifPass(String verifPass) {
//		this.verifPass = verifPass;
//	}

	public String updateUser() {

//		setErrorMsg(getErrorMsg() + userDAO.updateUser(userDTO, verifPass));
//		setErrorMsg(getErrorMsg() + userDAO.updateUser(userDTO));

		return "ok";
	}

	public String updatePassword() {

		if (pass.equals(confPass)) {
			userDAO.updateUserPassword(userDTO, pass);
		}
		return "ok";
	}

	public boolean getIsError() {
		if (errorMsg.equals("")) {
			isError = false;
		} else {
			isError = true;
		}
		return isError;
	}

	public void setIsError(boolean isError) {
		this.isError = isError;
	}

	public String getUserDomain() {
		return domainDAO.getDomain(userDTO.getIdDomain()).getName();
	}

	public void setUserDomain(String userDomain) {
		this.userDomain = userDomain;
	}

	public String getUsertype() {
		return usertypeDAO.getUsertype(userDTO.getIdUsertype()).getName();
	}

	public void setUsertype(String usertype) {
		this.usertype = usertype;
	}

	
	
	

}
